package interfaz;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PanelConfiguracion extends JPanel implements ActionListener 
{
	private JTextField txtPuerto;
	private JTextField txtIP;
	private JCheckBox chkGuardar;
	private JButton btnGuardar;
	
	private InterfazP2P interfaz;

	public PanelConfiguracion( InterfazP2P i, String ip, String puerto )
	{
		interfaz = i;
		setPreferredSize( new Dimension( 400,300 ));
		setSize( new Dimension( 400,300 ));
		
		JPanel panel = new JPanel( );
		panel.setMaximumSize( new Dimension( 300, 200 ) );
		panel.setLayout( new GridLayout( 4,2 ) );
		
		
		JLabel lblIP = new JLabel( "Puerto" );
		txtIP = new JTextField( ip );
		
		JLabel lblPuerto = new JLabel( "Direccion IP Multicast" );
		txtPuerto = new JTextField( puerto );
		
		btnGuardar = new JButton( "Guardar" );
		btnGuardar.addActionListener( this );
		btnGuardar.setActionCommand( "GUARDAR" );
		
		panel.add( lblIP );
		panel.add( txtIP );
		panel.add( lblPuerto );
		panel.add( txtPuerto );
		panel.add( btnGuardar );
		
		add( panel );
		
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		String cmd = e.getActionCommand();
		if( cmd.equals("GUARDAR") )
			interfaz.guardarConfig( txtIP.getText(), txtPuerto.getText() );
	}
}
